﻿<UserControl x:Class="Workbench.Presentation.ProjectTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:Workbench.Presentation"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="200">
    <DockPanel Margin="5">
        <Border  BorderBrush="Black" BorderThickness="0 0 0 0.25" 
                DockPanel.Dock="Top">
            <TextBlock DockPanel.Dock="Top" FontSize="18" Padding="0 5">Project Structure</TextBlock>
        </Border>
        
        <Border Margin="0 10 0 0" 
                BorderBrush="Black" 
                BorderThickness="0.7">
            <TreeView DockPanel.Dock="Top" BorderThickness="0"
                  ItemsSource="{Binding Path=RootNodes}"
                  PreviewMouseRightButtonDown="TreeView_PreviewMouseRightButtonDown">
                <TreeView.ItemContainerStyle>
                    <Style TargetType="{x:Type TreeViewItem}">
                        <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                        <Setter Property="FontWeight" Value="Normal"></Setter>
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True">
                                <Setter Property="FontWeight" Value="Bold"></Setter>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </TreeView.ItemContainerStyle>
                <TreeView.Resources>
                    <Style TargetType="{x:Type Image}">
                        <Setter Property="Width" Value="16"></Setter>
                        <Setter Property="Height" Value="16"></Setter>
                    </Style>

                    <HierarchicalDataTemplate DataType="{x:Type vm:ProjectDirectoryViewModel}" ItemsSource="{Binding Children}">
                        <StackPanel Margin="-1" Orientation="Horizontal" Tag="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}">
                            <StackPanel.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Add Existing File" Click="AddExistingFile_Click">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/text_file_add.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Add New Directory" Command="{Binding PlacementTarget.Tag.CreateDirectoryCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ContextMenu}}">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/folder_add.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Add Existing Directory" Click="AddExistingDirectory_Click">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/folder_existing.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <Separator/>
                                    <!--<MenuItem Header="Rename">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/folder_rename.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>-->
                                    <MenuItem Header="Remove" Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/folder_remove.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </StackPanel.ContextMenu>
                            <Image Source="/Workbench;component/Icons/folder.png" Margin="0 0 5 0" />
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </HierarchicalDataTemplate>

                    <DataTemplate DataType="{x:Type vm:ProjectFileViewModel}">
                        <StackPanel Margin="-1" Orientation="Horizontal" Tag="{Binding DataContext,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=UserControl}}">
                            <StackPanel.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Rename">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/text_file_rename.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Header="Remove"  Command="{Binding PlacementTarget.Tag.RemoveCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}">
                                        <MenuItem.Icon>
                                            <Image Source="/Workbench;component/Icons/text_file_remove.png" />
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </StackPanel.ContextMenu>
                            <Image Width="14" Height="14" Source="/Workbench;component/Icons/text_file.png" Margin="0 0 5 0" />
                            <CheckBox IsChecked="{Binding ContextIncluded}" />
                            <TextBlock Text="{Binding Name}" />
                        </StackPanel>
                    </DataTemplate>
                </TreeView.Resources>
            </TreeView>
        </Border>
    </DockPanel>
</UserControl>
